<?php

include '../app/common.php';
include '../check.php';

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>充值记录</title>
    <link rel="stylesheet" href="../component/pear/css/pear.css" />
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">订单号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="order_no" placeholder="" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">创建时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="create_time-start" name="create_time-start"
                               placeholder="开始时间" autocomplete="off">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="create_time-end" name="create_time-end"
                               placeholder="结束时间" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="dataTable" lay-filter="dataTable"></table>
    </div>
</div>

<script type="text/html" id="toolbar">
    <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
        <i class="layui-icon layui-icon-delete"></i>
        删除
    </button>
</script>

<script type="text/html" id="user-bar">
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
</script>

<script type="text/html" id="user-bar">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
</script>

<script type="text/html" id="user-enable">
    <input type="checkbox" name="enable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="user-enable" {{ d.enable== true ? 'checked' : '' }} />
</script>

<script type="text/html" id="user-sex">
    {{#if (d.sex == 1) { }}
    <span>男</span>
    {{# }else if(d.sex == 2){ }}
    <span>女</span>
    {{# } }}
</script>

<script type="text/html" id="user-login">
    {{#if (d.login == 0) { }}
    <span>在线</span>
    {{# }else if(d.sex == 1){ }}
    <span>离线</span>
    {{# } }}
</script>

<script type="text/html" id="user-createTime">
    {{layui.util.toDateString(d.createTime, 'yyyy-MM-dd')}}
</script>

<script src="../component/layui/layui.js"></script>
<script src="../component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'laydate'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        laydate.render({
            elem: "#create_time-start"
        });
        laydate.render({
            elem: "#create_time-end"
        })
        laydate.render({
            elem: "#update_time-start"
        });
        laydate.render({
            elem: "#update_time-end"
        })

        let cols = [
            [
                {
                    type: 'checkbox'
                },
                {field: 'order_no', title: '订单号', width: 200},
                {field: 'ip', title: '充值ip', width: 150},
                {field: 'type', title: '充值方式',  width: 100},
                {title: '订单金额',minWidth: 130, width: 130 },
                {field: 'name',title: '订单名称',width: 150},
                {
                    field: 'status', title: '订单状态', width: 150, templet: function (d) {
                        if (d.status == 1) {
                            return '<span style="color: #00a65a">已支付</span>';
                        } else  {
                            return '<span style="color: #a63542">未支付</span>';
                        }
                    }
                },
                {field: 'date', title: '充值时间', width: 180},
                {field: 'des',title: '订单详情',width: 150},
                {
                    title: '操作',
                    toolbar: '#user-bar',
                    align: 'center',
                    width: 130
                }

            ]

        ];
        table.render({
            elem: '#dataTable',
            url:  "ajax.class.php?act=getPayOrderData",
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });

        table.on('tool(dataTable)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        table.on('toolbar(dataTable)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            } else if (obj.event === 'recycle') {
                window.recycle(obj);
            }
        });

        form.on('submit(query)', function (data) {
            table.reload('dataTable', {
                where: data.field,
                page: {curr: 1}
            })

            laydate.render({
                elem: "#create_time-start"
            });
            laydate.render({
                elem: "#create_time-end"
            })
            laydate.render({
                elem: "#update_time-start"
            });
            laydate.render({
                elem: "#update_time-end"
            })
            return false;
        });
        if (typeof width !== 'number' || width === 0) {
            width = $(window).width() * 0.8;
        }
        if (typeof height !== 'number' || height === 0) {
            height = $(window).height() - 20;
        }


        window.remove = function (obj) {
            layer.confirm('确定要删除该数据', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url:  "ajax.class.php?act=removePayOrder" ,
                    data: {id: obj.data['id']},
                    dataType: 'json',
                    type: 'POST',
                    success: function (res) {
                        layer.close(loading);
                        if (res.code == 1) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                table.reload('dataTable');
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {
                    icon: 3,
                    time: 1000
                });
                return false;
            }
            var ids = []
            var hasCheck = table.checkStatus('dataTable')
            var hasCheckData = hasCheck.data
            if (hasCheckData.length > 0) {
                $.each(hasCheckData, function (index, element) {
                    ids.push(element.id)
                })
            }
            layer.confirm('确定要删除该数据', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url:  "ajax.class.php?act=batchRemovePayOrder&ids=" + ids,
                    dataType: 'json',
                    type: 'POST',
                    success: function (res) {
                        layer.close(loading);
                        if (res.code == 1) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                table.reload('dataTable');
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

      
    })
</script>
</body>
</html>
